//
//  SpecialPresentation.swift
//  HealthMonitoring
//
//  Created by 珠海正杰 on 2018/7/20.
//  Copyright © 2018年 YTYanK. All rights reserved.
//

import UIKit
import SwiftyJSON

class SpecialPresentation: HMViewController {
    
    let position = UILabel()
    let img = UIImageView()
    let bg = UIImageView()

    var btnData: [String : Any]? = ["btn1": "头部", "btn2": "脊椎", "btn3":"身体/体液", "btn4":"四肢"]
    var spJsonData: JSON = JSON()
    
    var btnLayout: [(String,String,String,String,Bool)]? = [("290","-20","0","0", false),("165","20","0","0", false),("55","20","0","0", false),("165","-20","0","0", false)]
    var btnAry: [UIButton]?
    
    override func setupView() {
        self.title = "专项报告"
        view.backgroundColor = UIColor.white
        
        view.addSubview(position)
        view.addSubview(position)
        view.addSubview(bg)
        view.addSubview(img)
        
   
        
//        view.addSubview(btn1)
//        view.addSubview(btn2)
//        view.addSubview(btn3)
//        view.addSubview(btn4)
        
        bg.topAlign(view: view, predicate: "0")
        bg.leadingAlign(view: view, predicate: "0")
        bg.trailingAlign(view: view, predicate: "0")
        bg.bottomAlign(view: view, predicate: "0")
        bg.image = UIImage(named: "presentationBg.png")
        
        img.topAlign(view: view, predicate: "60")
        img.leadingAlign(view: view, predicate: "0")
        img.trailingAlign(view: view,predicate: "0")
        img.bottomAlign(view: view, predicate: "-60")
        img.imgName(name: "aman.png")
        
  

        
        var i = 0
        for (v,k) in spJsonData {//btnData! {
            
            let btn = UIButton()
            btn.tag = i
            btn.dictionary = k.dictionaryObject
            
            btnAry?.append(btn)
            view.addSubview(btn)
            
//            let str = btnLayout![i].0
            btn.topAlign(view: view, predicate: btnLayout![i].0)
            if btnLayout![i].1.contains("-") {
                 btn.trailingAlign(view: view, predicate:  btnLayout![i].1)
            }else {
               btn.leadingAlign(view: view, predicate:  btnLayout![i].1)
            }
            btn.widthConstrain(predicate: "80")
            btn.heightConstrain(predicate: "30")
            btn.isSelected =  btnLayout![i].4
            btn.backgroundColor = configure.shareConfigure.HMColor1
            btn.layer.cornerRadius = 14
            btn.setTitle(k["name"].stringValue, for: .normal)
            btn.setTitleColor(UIColor.white, for: .normal)
            btn.addTarget(self, action: #selector(btnClick), for: .touchUpInside)
            i += 1
        }
           
        
    }
    
    @objc func btnClick(sender: UIButton) {
        print("---->>",sender)
        var ary = Array<String>()
        let special = SpecialTerm()
        special._signStr = (sender.titleLabel?.text)!
        special.stID = sender.dictionary!["id"] as! String
        let a = sender.dictionary!["subItem"] as! [Any]
        for v in a  {
           
            let dic = v as! Dictionary<String, Any>
             let str = dic["name"] as! String
            
            if sender.titleLabel?.text == "身体/体液" {
                if HMLoginParam.share.sex == 1  {
                    if str == "妇科" {
                    }else {
                        ary.append(str)
                        special.stData.append(v)
                    }
                   
                }else {
                    if str == "男科" {
                    }else {
                        ary.append(str)
                        special.stData.append(v)
                    }
                   
                }
            }else {
                ary.append(str)
                special.stData.append(v)
            }
            
           
            
        }
        
        if sender.titleLabel?.text == "头部" {
            special.btnData =  ary //["脑","眼睛","口腔","耳鼻喉","皮肤"]
            special.btnLayout = [("75","20","0","0", false),("220","10","0","0", false),("230","-10","0","0", false),("320","20","0","0", false),("325","-20","0","0", false)]
        }else if sender.titleLabel?.text == "脊椎" {
              special.btnData =  ary //["胸椎","腰椎","尾椎","颈椎","神经","皮肤"]
            special.btnLayout = [("100","20","0","0", false),("190","10","0","0", false),("280","20","0","0", false),("115","-10","0","0", false),("205","-10","0","0", false),("290","-20","0","0", false)]
        }else if sender.titleLabel?.text == "身体/体液" {
            special.btnData = ary //["气管","肺","肝胆脾","肛肠","妇科","血液/血管","皮肤", "心", "胃","肾", "体液"]
            special.btnLayout = [("110","20","0","0", false),  // 0
                                 ("125","-10","0","0", false), // 1
                                 ("160","10","0","0", false),  // 2
                                 ("195","-10","0","0", false),  // 3
                                 ("250","-20","0","0", false),
                                 ("210","20","0","0", false),
                                 ("255","20","0","0", false),  //
                                 ("300","10","0","0", false),  // 7
                                ("350","10","0","0", false), // 8
                                 ("400","20","0","0", false),  // 9
                                 ("360","-20","0","0", false)]
            
        }else {
              special.btnData =  ary //["肩","关节","肌肉","骨头","皮肤"]
              special.btnLayout = [("120","20","0","0", false),("245","20","0","0", false),("125","-20","0","0", false),("210","-20","0","0", false),("305","-20","0","0", false)]
        }
        
        
        self.pushViewController(special)
    }
}
